package com.siebre.picclife.asynctask.service.support;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.siebre.picclife.asynctask.TaskException;

public class TaskHandler {
	
	private final Object bean;
	
	private final Method method;
	
	public TaskHandler(Object bean, Method method) {
		this.bean = bean;
		this.method = method;
	}

	void handle(Object[] arguments) {
		try {
			method.invoke(bean, arguments);
		} catch (IllegalAccessException e) {
			throw new TaskException(String.format("failed to invoke method, method=%s, bean=%s", method, bean), e);
		} catch (InvocationTargetException e) {
			throw new TaskException(String.format("failed to invoke method, method=%s, bean=%s", method, bean), e.getCause());
		}
	}
	
	public Class<?>[] getArgumentTypes() {
		return method.getParameterTypes();
	}
}